import http from '../../utils/http'

/**
 * @description 医生相关API接口
 */

/**
 * 获取医生患者列表
 * @param {number} page - 页码
 * @param {number} limit - 每页数量
 * @returns {Promise} 患者列表
 */
export const reqDoctorPatients = (page = 1, limit = 10) => {
  return http.get('/doctor/patients', { page, limit })
}

/**
 * 获取患者详细信息
 * @param {number} patientId - 患者ID
 * @returns {Promise} 患者详细信息
 */
export const reqPatientDetail = (patientId) => {
  return http.get(`/doctor/patients/${patientId}`)
}

/**
 * 获取患者健康档案
 * @param {number} patientId - 患者ID
 * @returns {Promise} 健康档案
 */
export const reqPatientHealthRecord = (patientId) => {
  return http.get(`/doctor/patients/${patientId}/health-record`)
}

/**
 * 获取患者饮食历史
 * @param {number} patientId - 患者ID
 * @param {string} startDate - 开始日期
 * @param {string} endDate - 结束日期
 * @returns {Promise} 饮食历史
 */
export const reqPatientDietHistory = (patientId, startDate, endDate) => {
  return http.get(`/doctor/patients/${patientId}/diet-history`, { startDate, endDate })
}

/**
 * 更新医生个人信息
 * @param {Object} profileData - 医生档案数据
 * @returns {Promise} 更新结果
 */
export const reqUpdateDoctorProfile = (profileData) => {
  return http.post('/doctor/profile', profileData)
}

/**
 * 获取医生个人信息
 * @returns {Promise} 医生档案
 */
export const reqDoctorProfile = () => {
  return http.get('/doctor/profile')
}

/**
 * 获取医生消息列表
 * @param {number} page - 页码
 * @param {number} limit - 每页数量
 * @returns {Promise} 消息列表
 */
export const reqDoctorMessages = (page = 1, limit = 20) => {
  return http.get('/doctor/messages', { page, limit })
}

/**
 * 获取与特定患者的聊天记录
 * @param {number} patientId - 患者ID
 * @param {number} page - 页码
 * @param {number} limit - 每页数量
 * @returns {Promise} 聊天记录
 */
export const reqChatHistory = (patientId, page = 1, limit = 50) => {
  return http.get(`/doctor/chat/${patientId}`, { page, limit })
}

/**
 * 发送消息给患者
 * @param {number} patientId - 患者ID
 * @param {string} content - 消息内容
 * @param {string} type - 消息类型 (text/image/file)
 * @returns {Promise} 发送结果
 */
export const reqSendMessage = (patientId, content, type = 'text') => {
  return http.post('/doctor/messages', {
    patientId,
    content,
    type
  })
}

/**
 * 标记消息为已读
 * @param {number} messageId - 消息ID
 * @returns {Promise} 标记结果
 */
export const reqMarkMessageRead = (messageId) => {
  return http.post(`/doctor/messages/${messageId}/read`)
}

/**
 * 添加新患者
 * @param {Object} patientData - 患者数据
 * @returns {Promise} 添加结果
 */
export const reqAddPatient = (patientData) => {
  return http.post('/doctor/patients', patientData)
}

/**
 * 更新患者信息
 * @param {number} patientId - 患者ID
 * @param {Object} patientData - 患者数据
 * @returns {Promise} 更新结果
 */
export const reqUpdatePatient = (patientId, patientData) => {
  return http.put(`/doctor/patients/${patientId}`, patientData)
}

/**
 * 删除患者
 * @param {number} patientId - 患者ID
 * @returns {Promise} 删除结果
 */
export const reqDeletePatient = (patientId) => {
  return http.delete(`/doctor/patients/${patientId}`)
}

/**
 * 获取医生统计数据
 * @returns {Promise} 统计数据
 */
export const reqDoctorStats = () => {
  return http.get('/doctor/stats')
}

/**
 * 获取医生排班信息
 * @param {string} date - 日期
 * @returns {Promise} 排班信息
 */
export const reqDoctorSchedule = (date) => {
  return http.get('/doctor/schedule', { date })
}

/**
 * 更新医生排班
 * @param {Object} scheduleData - 排班数据
 * @returns {Promise} 更新结果
 */
export const reqUpdateSchedule = (scheduleData) => {
  return http.post('/doctor/schedule', scheduleData)
}
